package com.hdax.dmw.item.mapstruct;

import com.hdax.dmw.dtos.item.HotItemDto;
import com.hdax.dmw.dtos.item.IndexNavDto;
import com.hdax.dmw.item.DmItemType;
import com.hdax.dmw.item.service.DmItemService;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper(componentModel = "spring")
public abstract class IndexNavDtoMapper {

    @Mappings({
          @Mapping(target = "hotItems",
                  expression = "java(transferHotItems(source.getId()))")
    })
    public abstract IndexNavDto toTarget(DmItemType source);
    public abstract List<IndexNavDto> toTargetList(List<DmItemType> sources);

    @Autowired
    private DmItemService itemService;

    protected List<HotItemDto> transferHotItems(Long itemType1Id){
        return itemService.getHotItems(itemType1Id);
    }
}
